import 'package:ai_data_capture/bean/TaskBean.dart';
import 'package:ai_data_capture/bean/TemplateBean.dart';
import 'package:ai_data_capture/req/network_service.dart';

class TaskApi {
  static Future<List<TaskBean>> getTaskList() async {
    var res = await NetworkService.post(url: "auto/get_task_list", map: {});
    return res?.getTypedList((m) => TaskBean.fromJson(m)) ?? [];
  }

  static Future<List<TemplateBean>> getTemplates() async {
    var res = await NetworkService.post(url: "auto/get_templates", map: {});
    return res?.getTypedList((m) => TemplateBean.fromJson(m)) ?? [];
  }

  static addTemp(
      {required String? id,
      required String configid,
      required String flowid,
      required String desc}) async {
    await NetworkService.post(url: "auto/add_template", map: {
      "id": id,
      "config_id": configid,
      "flow_id": flowid,
      "description": desc
    });
    return [];
  }

  static deleteTemplate(String id) async {
    await NetworkService.post(url: "auto/delete_template", map: {"id": id});
  }

  static addTempToChannel(TemplateBean bean) async {
    await NetworkService.post(
        url: "auto/add_temp_to_channel", map: bean.toJson());
  }

  static removeFinishedTask() async {
    await NetworkService.post(url: "auto/remove_finished_task", map: {});
  }
}
